﻿/**  版本信息模板在安装目录下，可自行修改。
* t_reply.cs
*
* 功 能： N/A
* 类 名： t_reply
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2014/11/29 20:35:40   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace XinKuaiJi.DAL
{
	/// <summary>
	/// 数据访问类:t_reply
	/// </summary>
	public partial class t_reply
	{
		public t_reply()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(long reply_id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from t_reply");
			strSql.Append(" where reply_id=@reply_id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@reply_id", MySqlDbType.Int64,64)			};
			parameters[0].Value = reply_id;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(XinKuaiJi.Model.t_reply model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into t_reply(");
			strSql.Append("reply_id,msg_id,user_id,content,time,I1,I2,I3,C1,C2,C3)");
			strSql.Append(" values (");
			strSql.Append("@reply_id,@msg_id,@user_id,@content,@time,@I1,@I2,@I3,@C1,@C2,@C3)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@reply_id", MySqlDbType.Int64,64),
					new MySqlParameter("@msg_id", MySqlDbType.Int64,64),
					new MySqlParameter("@user_id", MySqlDbType.Int64,64),
					new MySqlParameter("@content", MySqlDbType.VarChar,200),
					new MySqlParameter("@time", MySqlDbType.DateTime),
					new MySqlParameter("@I1", MySqlDbType.Int64,64),
					new MySqlParameter("@I2", MySqlDbType.Int64,64),
					new MySqlParameter("@I3", MySqlDbType.Int64,64),
					new MySqlParameter("@C1", MySqlDbType.VarChar,200),
					new MySqlParameter("@C2", MySqlDbType.VarChar,200),
					new MySqlParameter("@C3", MySqlDbType.VarChar,200)};
			parameters[0].Value = model.reply_id;
			parameters[1].Value = model.msg_id;
			parameters[2].Value = model.user_id;
			parameters[3].Value = model.content;
			parameters[4].Value = model.time;
			parameters[5].Value = model.I1;
			parameters[6].Value = model.I2;
			parameters[7].Value = model.I3;
			parameters[8].Value = model.C1;
			parameters[9].Value = model.C2;
			parameters[10].Value = model.C3;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(XinKuaiJi.Model.t_reply model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update t_reply set ");
			strSql.Append("msg_id=@msg_id,");
			strSql.Append("user_id=@user_id,");
			strSql.Append("content=@content,");
			strSql.Append("time=@time,");
			strSql.Append("I1=@I1,");
			strSql.Append("I2=@I2,");
			strSql.Append("I3=@I3,");
			strSql.Append("C1=@C1,");
			strSql.Append("C2=@C2,");
			strSql.Append("C3=@C3");
			strSql.Append(" where reply_id=@reply_id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@msg_id", MySqlDbType.Int64,64),
					new MySqlParameter("@user_id", MySqlDbType.Int64,64),
					new MySqlParameter("@content", MySqlDbType.VarChar,200),
					new MySqlParameter("@time", MySqlDbType.DateTime),
					new MySqlParameter("@I1", MySqlDbType.Int64,64),
					new MySqlParameter("@I2", MySqlDbType.Int64,64),
					new MySqlParameter("@I3", MySqlDbType.Int64,64),
					new MySqlParameter("@C1", MySqlDbType.VarChar,200),
					new MySqlParameter("@C2", MySqlDbType.VarChar,200),
					new MySqlParameter("@C3", MySqlDbType.VarChar,200),
					new MySqlParameter("@reply_id", MySqlDbType.Int64,64)};
			parameters[0].Value = model.msg_id;
			parameters[1].Value = model.user_id;
			parameters[2].Value = model.content;
			parameters[3].Value = model.time;
			parameters[4].Value = model.I1;
			parameters[5].Value = model.I2;
			parameters[6].Value = model.I3;
			parameters[7].Value = model.C1;
			parameters[8].Value = model.C2;
			parameters[9].Value = model.C3;
			parameters[10].Value = model.reply_id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(long reply_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from t_reply ");
			strSql.Append(" where reply_id=@reply_id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@reply_id", MySqlDbType.Int64,64)			};
			parameters[0].Value = reply_id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string reply_idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from t_reply ");
			strSql.Append(" where reply_id in ("+reply_idlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public XinKuaiJi.Model.t_reply GetModel(long reply_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select reply_id,msg_id,user_id,content,time,I1,I2,I3,C1,C2,C3 from t_reply ");
			strSql.Append(" where reply_id=@reply_id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@reply_id", MySqlDbType.Int64,64)			};
			parameters[0].Value = reply_id;

			XinKuaiJi.Model.t_reply model=new XinKuaiJi.Model.t_reply();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public XinKuaiJi.Model.t_reply DataRowToModel(DataRow row)
		{
			XinKuaiJi.Model.t_reply model=new XinKuaiJi.Model.t_reply();
			if (row != null)
			{
				if(row["reply_id"]!=null && row["reply_id"].ToString()!="")
				{
					model.reply_id=long.Parse(row["reply_id"].ToString());
				}
				if(row["msg_id"]!=null && row["msg_id"].ToString()!="")
				{
					model.msg_id=long.Parse(row["msg_id"].ToString());
				}
				if(row["user_id"]!=null && row["user_id"].ToString()!="")
				{
					model.user_id=long.Parse(row["user_id"].ToString());
				}
				if(row["content"]!=null)
				{
					model.content=row["content"].ToString();
				}
				if(row["time"]!=null && row["time"].ToString()!="")
				{
					model.time=DateTime.Parse(row["time"].ToString());
				}
				if(row["I1"]!=null && row["I1"].ToString()!="")
				{
					model.I1=long.Parse(row["I1"].ToString());
				}
				if(row["I2"]!=null && row["I2"].ToString()!="")
				{
					model.I2=long.Parse(row["I2"].ToString());
				}
				if(row["I3"]!=null && row["I3"].ToString()!="")
				{
					model.I3=long.Parse(row["I3"].ToString());
				}
				if(row["C1"]!=null)
				{
					model.C1=row["C1"].ToString();
				}
				if(row["C2"]!=null)
				{
					model.C2=row["C2"].ToString();
				}
				if(row["C3"]!=null)
				{
					model.C3=row["C3"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select reply_id,msg_id,user_id,content,time,I1,I2,I3,C1,C2,C3 ");
			strSql.Append(" FROM t_reply ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM t_reply ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.reply_id desc");
			}
			strSql.Append(")AS Row, T.*  from t_reply T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "t_reply";
			parameters[1].Value = "reply_id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

